package com.yt.xiao.code.generate.dal.po;

import com.yt.xiao.code.generate.util.CgUtil;


public class Column {

    public Column() {
    }

    public Column(String code, int sqlType, int length) {
        this.length = length;
        this.setCode(code);
        this.setSqlType(sqlType);
    }

    public Column(String code, int sqlType, int length, String comment) {
        this.length = length;
        this.setCode(code);
        this.setSqlType(sqlType);
        this.comment = comment;
    }

    /**
     * 根据code驼峰命名生成
     */
    private String name;
    /**
     * 数据库表字段名称
     */
    private String code;
    /**
     * 字段长度
     */
    private int length;
    /**
     * 字段注释
     */
    private String comment;
    /**
     * java 类型
     */
    private String javaType;
    /**
     * jdbc 短类型名称
     */
    private String jdbcTypeName;
    /**
     * java.sql.Types 定义的字段类型
     */
    private int sqlType;
    /**
     * java.sql.Types
     */
    private String sqlTypeName;

    /**
     * 是否是自增列:仅当字段是主键时有效
     */
    private boolean autoincrement = false;
    
    /**
     * 是否是主键
     */
    private boolean primaryKey=false;

    public String getName() {
        return name;
    }
    public String getCode() {
        return code;
    }
    public int getLength() {
        return length;
    }
    public String getComment() {
        return comment;
    }
    public int getSqlType() {
        return sqlType;
    }
    public String getJavaType() {
        return javaType;
    }
    public String getSqlTypeName() {
        return sqlTypeName;
    }




    public void setName(String name) {
        this.name = name;
    }
    public void setCode(String code) {
        this.code = code;
        this.name = CgUtil.toCamelCase(code);
    }
    public void setLength(int length) {
        this.length = length;
    }
    public void setSqlType(int sqlType) {
        this.sqlType = sqlType;
        this.javaType = CgUtil.getJavaType(sqlType);
        this.sqlTypeName=CgUtil.getSqlTypeName(sqlType);
        this.jdbcTypeName=this.sqlTypeName.substring(15);
    }
    public void setJavaType(String javaType) {
        this.javaType = javaType;
    }
    public void setComment(String comment) {
        this.comment = comment;
    }
    public boolean isAutoincrement() {
        return autoincrement;
    }
    public void setAutoincrement(boolean autoincrement) {
        this.autoincrement = autoincrement;
    }
    public void setSqlTypeName(String sqlTypeName) {
        this.sqlTypeName = sqlTypeName;
    }

    public final String getJdbcTypeName() {
        return jdbcTypeName;
    }
    public final void setJdbcTypeName(String jdbcTypeName) {
        this.jdbcTypeName = jdbcTypeName;
    }

    /**
     * @return the primaryKey
     */
    public boolean isPrimaryKey() {
        return primaryKey;
    }

    /**
     * @param primaryKey the primaryKey to set
     */
    public void setPrimaryKey(boolean primaryKey) {
        this.primaryKey = primaryKey;
    }
}
